package hhq.demo.listener;

import hhq.demo.config.Conf;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.io.File;

/**
 * 需要自己配置，在 META-INF 中
 */
public class MyRunListener implements SpringApplicationRunListener {

    public MyRunListener(SpringApplication application, String[] args){

    }

    @Override
    public void starting() {
    }

    @Override
    public void environmentPrepared(ConfigurableEnvironment environment) {
    }

    @Override
    public void contextPrepared(ConfigurableApplicationContext context) {
    }

    @Override
    public void contextLoaded(ConfigurableApplicationContext context) {
    }
    @Override
    public void started(ConfigurableApplicationContext context) {
        Conf conf = context.getBean(Conf.class);
        File file_tmp = new File(conf.filePath);
        File file_explore = new File(conf.ExplorerPath);
        boolean flag=true;
        if( ! file_tmp.exists() ){
            System.out.println("临时文件路径不存在："+conf.filePath);
            flag = false;
        }else{
            System.out.println("临时文件路径存在："+conf.filePath);
        }
        if( ! file_explore.exists() ){
            System.out.println("云盘文件路径不存在："+conf.ExplorerPath);
            flag = false;
        }else{
            System.out.println("云盘文件路径存在："+conf.ExplorerPath);
        }
        if(!flag){
            System.exit(-1);
        }
    }

    @Override
    public void running(ConfigurableApplicationContext context) {
    }

    @Override
    public void failed(ConfigurableApplicationContext context, Throwable exception) {
    }


}
